exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
  __before() {// 前置操作，在action执行，返回false则终止当前控制器
  }

  getPostListAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      // 获取所有岗位列表
      const aj = think.ajaxJson();
      const data = _this.get('page,pageSize,post_name');
      const PostService = think.service('sys/PostService');
      const res = yield PostService.getPostList(data);
      if (res && res.error) {
        return _this.errorJson('岗位列表查询失败');
      } else {
        return _this.successJson(res);
      }
    })();
  }

  savePostInfoAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      // 保存岗位信息
      let saveData = {};
      const userData = _this2.getUser();
      if (_this2.post('id')) {
        saveData = _this2.post('id,post_name,post_type,post_sort,remarks');
      } else {
        saveData = _this2.post('post_name,post_type,post_code,post_sort,remarks');
        saveData.create_by = userData.userId;
        saveData.create_date = new Date();
      }
      saveData.update_by = userData.userId;
      saveData.update_date = new Date();
      const PostService = think.service('sys/PostService');
      const res = yield PostService.savePostInfo(saveData);
      if (res) {
        if (res.error) {
          return _this2.errorJson('岗位信息保存失败');
        } else {
          return _this2.successJson();
        }
      } else {
        return _this2.errorJson('岗位名称或编码重复，请重新输入');
      }
    })();
  }

  delPostInfoAction() {
    var _this3 = this;

    return _asyncToGenerator(function* () {
      // 删除岗位
      const delData = {
        id: _this3.post('id')
      };
      const PostService = think.service('sys/PostService');
      const res = yield PostService.delPostInfo(delData);
      if (res && res.error) {
        return _this3.errorJson('岗位信息删除失败');
      } else {
        return _this3.successJson();
      }
    })();
  }

  getAllPostAction() {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      const PostService = think.service('sys/PostService');
      const res = yield PostService.getAllPost();
      if (res && res.error) {
        return _this4.errorJson('岗位列表获取失败');
      } else {
        return _this4.successJson(res);
      }
    })();
  }

  saveUserPostAction() {
    var _this5 = this;

    return _asyncToGenerator(function* () {
      const PostService = think.service('sys/PostService');
      const data = {
        user_id: _this5.post('user_id'),
        delList: _this5.post('delList'),
        addList: _this5.post('addList')
      };
      const res = yield PostService.saveUserPost(data);
      if (res && res.error) {
        return _this5.errorJson('用户岗位关联失败');
      } else {
        return _this5.successJson(res);
      }
    })();
  }
  __after() {// 后置操作,在action调用之后执行

  }
  __call() {// 魔术函数

  }
};
;